package com.tanhua.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentsController {
    @Autowired
    private CommentsService commentsService;

    /**
     * 发布评论
     *
     * @param map
     * @return
     */
    @PostMapping
    public ResponseEntity Release(@RequestBody Map map) {
        String movementId = (String) map.get("movementId");//动态id
        String comment = (String) map.get("comment");//评论内容
        commentsService.Release(movementId, comment);
        return ResponseEntity.ok(null);
    }

    /**
     * 查询评论列表
     *
     * @param page
     * @param pagesize
     * @param movementId
     * @return
     */
    @GetMapping
    public ResponseEntity Lookup(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pagesize,
                                 String movementId) {
        PageResult pr = commentsService.Lookup(page, pagesize, movementId);
        return ResponseEntity.ok(pr);
    }


}
